package com.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author cheyinbo
 * @description TODO
 * @date 2021/9/29 9:10
 */
@RestController
@Slf4j
public class ScanController {

    @GetMapping("/test")
    public String test() {
        return "success";
    }

    @PostMapping("/scan")
    public String scan(@RequestParam("file") MultipartFile[] files) throws IOException {
        for (MultipartFile file : files) {
            String filename = file.getOriginalFilename();
            File save = new File("E:\\"+filename);
            if (!save.exists()) {
                save.mkdirs();
            }
            file.transferTo(save);
            String cmd = String.format("tesseract "+ "E:\\"+filename + " E:\\res" + " -l chi_sim");
            Runtime.getRuntime().exec(new String[]{ "cmd", "/c", cmd});
        }
        return "hhh";
    }

}
